package com.jsu.sender;

import com.jsu.config.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class MessageSender {


    private static RabbitTemplate rabbitTemplate;

    /**
     * 直播订阅通知
     * @param liveName 议程名
     * @param id 议程id
     */
    public static void sendAgendaLive(String liveName,String id){
        String message = liveName + ":" + id;
        log.info("sendAgendaLive message:{}",message);
        rabbitTemplate.convertAndSend(RabbitMqConfig.FANOUT_QUEUE_NAME, message);
    }

    public static void sendAcitivityLive(String liveName,String id){
        String message = liveName + ":" + id;
        rabbitTemplate.convertAndSend(RabbitMqConfig.FANOUT_QUEUE_NAME, message);
    }

    public static void sendDelayQueue(String message, Integer delayTime) {

        // 三个参数
        rabbitTemplate.convertAndSend(RabbitMqConfig.DELAY_EXCHANGE_NAME,
                RabbitMqConfig.DELAY_QUEUE_ROUTING_KEY,message,
                message1 -> {
                    //设置延时时间
                    message1.getMessageProperties().setDelay(delayTime);
                    return message1;
                });
    }


}
